import createDraw from '../utils/Draw'
import { ref } from 'vue'
import { Point } from '../utils/Point'
export default function (map, source) {
  const visible = ref(false)
  const positionValue = ref(null)
  /* 定义画笔 */
  const draw = ref(null)

  /* 调用画笔 */
  const addPointEvent = (map) => {
    draw.value = createDraw({
      type: 'Point',
      source,
      callback: handleSuccess,
    })
    map.value.addInteraction(draw.value)
    function handleSuccess(e) {
      map.value.removeInteraction(draw.value)
      visible.value = true
      positionValue.value = e.feature.getGeometry().flatCoordinates
    }
  }

  return { addPointEvent, visible, positionValue }
}
